<template>
  <div>
    <div id="xieyi" style="margin-bottom: 60px">
      <!--已签名金卡协议-->
      <p class="text" v-html="agreement"></p>
      <div v-if="isNeedEleSeal==0">
        <img width="100%" height="250px" :src="accountelesign.signStr" v-if="haveSign"/>
      </div>
      <div style="font-size: 14px" v-if="isNeedEleSeal==1&& eleSealImg">
        <p>甲方：{{companyName}}</p>
        <p>乙方（签署人）：<img width="120px" height="40px" style="padding-top: 10px" :src="accountelesign.signStr"
                        v-if="haveSign"/></p>
        <p style="padding-top: 30px">签订日期:{{signDate}}</p>
      </div>
      <div style="background-color: rgba(255, 255, 255, 255)" v-if="isNeedEleSeal==1">
        <img width="183" height="183" :src="eleSealImg"
             style="position: absolute;margin-top: -270px;transform: rotate(90deg);">
      </div>
    </div>
    <!--<p class="offer" @click="screenShots()">截图</p>-->
  </div>
</template>

<script type="text/ecmascript-6">
  import {getAccountgoodsAgreement} from '../../../test/unit/http'
  import html2canvas from "html2canvas";
  import {Toast} from 'we-vue'

  export default {
    name: 'xieyi',
    props: {},
    data() {
      return {
        goods: {},
        haveSign: false,
        agreement: '',
        accountelesign: {},
        signDate: '',
        companyName: '',
        isNeedEleSeal: 0,
        eleSealImg: '',
      };
    },
    methods: {
      getAccountgoodsAgreementData(params) {
        getAccountgoodsAgreement(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.agreement = res.object.agreement;
            this.haveSign = res.object.haveSign;
            if (this.haveSign) {
              this.accountelesign = res.object.accountelesign;
              let isNeedEleSeal = res.object.isNeedEleSeal;
              this.isNeedEleSeal = isNeedEleSeal
              if (isNeedEleSeal == 1) {
                let eleSealImg = res.object.eleSealImg;
                this.eleSealImg = eleSealImg
                this.signDate = res.object.signDate;
                this.companyName = res.object.companyName;
              }
            }
          } else {
            Toast.fail(res.info);
          }
        })
      },
      screenShots() {
        window.pageYOffset = 0;
        document.documentElement.scrollTop = 0;
        document.body.scrollTop = 0
        html2canvas(document.getElementById('xieyi'),
          {
            useCORS: true,//支持图片跨域
            scale: 1,//设置放大的倍数
          }
        ).then(canvas => {
          // toDataURL :图片格式转成 base64
          this.downloadImage(canvas.toDataURL('image/png'))
        })
      },
      //下载图片
      downloadImage(url) {
        // 如果是在网页中可以直接创建一个 a 标签直接下载
        let a = document.createElement('a')
        a.href = url
        a.download = '截图'
        a.click()
      }
    },
    created() {
      let accountGoodsId = this.$route.query.accountGoodsId;
      this.getAccountgoodsAgreementData({accountGoodsId: accountGoodsId});
    },
    mounted() {
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .divider {
    background-color: #eee;
    height: 20px;
    width: 100%;
    text-align: left;
    padding: 3px;

    .btn {
      button {
        color: #fff;
        border: none;
        width: calc(35% - 50px);
        margin-left: 30px;
      }

      :last-child {
        background-color: #f9964e;

      }

      :first-child {
        background-color: #ccc;
        margin-right: 20px;
      }
    }
  }

  .title {
    font-size: 20px;
    color: #111;
    font-weight: 700;
    padding: 10px;
  }

  .text {
    font-size: 15px;
    color: #666;
    line-height: 25px;
    text-indent: 30px;
    text-align: left;
    padding: -300px 10px 10px;
  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-image: linear-gradient(to right, #f9964e, #ff8551);
    height: 50px;
    line-height: 50px;
    color: #fff;
  }


</style>
